home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / cnet / cn305c_2.lha / programming / empty.c < prev    next >
C/C++ Source or Header  |  1994-01-28  |  10KB  |  510 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /*    CNet AMIGA 3.0  C language interface routines and examples    */
  4. /*                                    */
  5. /*    © 1993    Perspective Software ... this code may be freely    */
  6. /*        ditributed to and used by registered CNet owners    */
  7. /*        EXCLUSIVELY.  Other distribution is in violation     */
  8. /*        of copyright laws.                    */
  9. /*                                    */
  10. /************************************************************************/
  11.  
  12. void CallHost( UBYTE c );
  13. void ShutDown( char *spawn );
  14.  
  15. struct MsgPort  *replyp;    /* Some commnunication details ...    */
  16. struct CPort    *cport;
  17. struct CMessage  cmess;
  18.  
  19. struct    MainPort  *myp;        /* Pointer to CNet port--ALL info!    */
  20. struct    PortData  *z;
  21.  
  22. char    **bm;
  23. struct    Library *CNetBase = NULL;
  24. struct    SignalSemaphore *SEM;
  25.                 /* put your other GLOBALS here        */
  26.  
  27.  
  28. void main( int argc, char **argv )
  29. {
  30.     if( argc<2 || !(cport = (struct CPort *)FindPort( argv[1] )) ) {
  31.         printf("This is a CNet C program.\n");
  32.         exit(0);
  33.     }
  34.  
  35.     if( !(replyp = CreatePort( 0,0 )))
  36.         exit(0);
  37.  
  38.     cmess.cn_Message.mn_ReplyPort   = replyp;
  39.     cmess.cn_Message.mn_Length      = sizeof( struct CMessage );
  40.     cmess.cn_Message.mn_Node.ln_Name= "cstuff";
  41.  
  42.     if( cport->ack != 30 ) {    /* right CNet version running? */
  43.         cport->ack = 1;
  44.         goto err;
  45.     }
  46.  
  47.     cport->ack = 0;
  48.  
  49.     z        =    cport->zp;
  50.     myp        =    cport->myp;
  51.     SEM        =    myp->SEM;
  52.     bm        =    z->bm;
  53.  
  54.     if( !(CNetBase = OpenLibrary( "cnet.library",0 )) )
  55.         goto err0;
  56.  
  57.     /* put your program here */
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.     /* get back to CNet */
  65.  
  66. err0:    ShutDown( NULL );
  67.  
  68. err:    DeletePort( replyp );
  69.  
  70.     if( CNetBase ) CloseLibrary( CNetBase );
  71.  
  72.     exit(0);
  73. }
  74.  
  75. void ShutDown( char *spawn )            /* another file to run? */
  76. {
  77.     if( spawn )
  78.         strcpy( z->CSpawn, spawn );
  79.  
  80.     CallHost( 0 );
  81. }
  82.  
  83. void CallHost( UBYTE c )
  84. {
  85.     cmess.command = c;
  86.     PutMsg  ( (struct MsgPort *)cport, (struct Message *)&cmess );
  87.     WaitPort( replyp );
  88.     GetMsg  ( replyp );
  89. }
  90.  
  91. void PutText( char *text )
  92. {
  93.     cmess.arg1 = (ULONG)text;    /* text to print        */
  94.     CallHost( 1 );
  95. }
  96.  
  97. void PutA( void )
  98. {
  99.     PutText( z->ABuffer );
  100. }
  101.  
  102. /*    flags are:
  103.             1:    All capitalized
  104.             2:    FILENAME.  Don't allow =":;/ or asterisk
  105.             4:    Begin with existing z.InBuffer
  106.             8:    Chop leading spaces
  107.            16:    Force 1st letter of word caps
  108.            32:    Force all others lower case
  109.            64:    Numeric input only
  110.           128:    Print input box (.)
  111.           256:    DO allow MCI
  112.           512:    HANDLES/SPECIAL.  Don't allow ^_`{|}~@
  113.          1024:    Exit for . or / at beginning of line
  114.          2048:    Exit for backspace at beginning of line
  115.          4096:    Do not allow OLM's to appear while editing
  116.          8192:    Allow Chat break in at this prompt. COMMAND PROMPT.
  117.         16384:    Don't allow SPACE, either
  118.         32768:  DON'T ALLOW MOVEMENT
  119. */
  120.  
  121. int EnterLine( UBYTE len, USHORT flags, char *prompt )
  122. {
  123.     cmess.arg1 = (ULONG)len;    /* how many chars max to input    */
  124.     cmess.arg2 = (ULONG)flags;    /* 1=UpperCase            */
  125.     cmess.arg3 = (ULONG)prompt;    /* text to print before input    */
  126.     CallHost( 2 );            /* result is in z->InBuffer    */
  127.     return( (int)strlen( z->InBuffer ));
  128. }
  129.  
  130. char OneKey( void )            /* Stop until a key is pressed    */
  131. {
  132.     CallHost( 3 );
  133.     return( (char)cmess.result );
  134. }
  135.  
  136. void EnterPassword( UBYTE len )
  137. {
  138.     cmess.arg1 = (ULONG)len;    /* max number of characters */
  139.     CallHost( 4 );
  140. }
  141.  
  142. long CommonCommands( void )        /* Check z->InBuffer for Chat, OLM, etc */
  143. {
  144.     CallHost( 5 );
  145.     return( (long)cmess.result );
  146. }
  147.  
  148. UBYTE ReadFile( char *path, UBYTE flags )
  149. {
  150.     cmess.arg1 = (ULONG)path;
  151.     cmess.arg2 = (ULONG)flags;    /* 1 = print File Not Found    */
  152.     CallHost( 6 );
  153.     return( (UBYTE)cmess.result );        /* FALSE if File Not Found    */
  154. }
  155.  
  156. void SetDoing( char *what )
  157. {
  158.     cmess.arg1 = (ULONG)what;
  159.     CallHost( 7 );
  160. }
  161.  
  162. void CallEditor( short max, short inlines )
  163. {
  164.     cmess.arg1 = (ULONG)max;    /* Maximum number of lines (250)*/
  165.     cmess.arg2 = (ULONG)inlines;    /* TRUE/FALSE use existing _edbuff? */
  166.     CallHost( 8 );
  167. }
  168.  
  169. UBYTE ReadGraphics( char *path, char flags )
  170. {
  171.     cmess.arg1 = (ULONG)path;
  172.     cmess.arg2 = (ULONG)flags;    /* 1 = print File Not Found    */
  173.     CallHost( 9 );
  174.     return( (UBYTE)cmess.result );        /* FALSE if File Not Found    */
  175. }
  176.  
  177. void MakeDate( struct IsDate *date, char *output )
  178. {
  179.     cmess.arg1 = (ULONG)date;
  180.     cmess.arg2 = (ULONG)output;
  181.     CallHost( 10 );
  182. }
  183.  
  184. UBYTE ReadAccount( short id, struct UserData *user )
  185. {
  186.     cmess.arg1 = (ULONG)id;
  187.     cmess.arg2 = (ULONG)user;
  188.     CallHost( 11 );
  189.     return( (UBYTE)cmess.result );
  190. }
  191.  
  192. UBYTE SaveAccount( struct UserData *user, short id )
  193. {
  194.     cmess.arg1 = (ULONG)user;
  195.     cmess.arg2 = (ULONG)id;
  196.     CallHost( 12 );
  197.     return( (UBYTE)cmess.result );
  198. }
  199.  
  200. UBYTE AddCharge( short n, short a )
  201. {
  202.     cmess.arg1 = (ULONG)n;
  203.     cmess.arg2 = (ULONG)a;
  204.     CallHost( 13 );
  205.     return( (UBYTE)cmess.result );
  206. }
  207.  
  208. UBYTE CheckBalance( short n, short a )
  209. {
  210.     cmess.arg1 = (ULONG)n;
  211.     cmess.arg2 = (ULONG)a;
  212.     CallHost( 14 );
  213.     return( (UBYTE)cmess.result );
  214. }
  215.  
  216. int EnterText( char firstchar, short maxchars, short perline, short maxlines )
  217. {
  218.     cmess.arg1 = (ULONG)firstchar;
  219.     cmess.arg2 = (ULONG)maxchars;
  220.     cmess.arg3 = (ULONG)perline;
  221.     cmess.arg4 = (ULONG)maxlines;
  222.     CallHost( 15 );
  223.     return( (int)cmess.result );
  224. }
  225.  
  226. long ConferenceWait( short a )
  227. {
  228.     cmess.arg1 = (ULONG) a;
  229.     CallHost( 16 );
  230.     return( (long)cmess.result );
  231. }
  232.  
  233. void CheckChanges( void )
  234. {
  235.     CallHost( 17 );
  236. }
  237.  
  238. long ConvertAccess( char *s )
  239. {
  240.     cmess.arg1 = (ULONG)s;
  241.     CallHost( 18 );
  242.     return( (long)cmess.result );
  243. }
  244.  
  245. long GetFree( char *s, UBYTE q )
  246. {
  247.     cmess.arg1 = (ULONG)s;
  248.     cmess.arg2 = (ULONG)q;
  249.     CallHost( 19 );
  250.     return( (long)cmess.result );
  251. }
  252.  
  253. short FindAccount( char *a, struct UserData *b )
  254. {
  255.     cmess.arg1 = (ULONG)a;
  256.     cmess.arg2 = (ULONG)b;
  257.     CallHost( 20 );
  258.     return( (short)cmess.result );
  259. }
  260.  
  261. void CheckFlowControl( void )
  262. {
  263.     CallHost( 21 );
  264. }
  265.  
  266. long ListDir( UBYTE a, UBYTE b, struct IsDate *c )
  267. {
  268.     cmess.arg1 = (ULONG)a;
  269.     cmess.arg2 = (ULONG)b;
  270.     cmess.arg3 = (ULONG)c;
  271.     CallHost( 22 );
  272.     return( (long)cmess.result );
  273. }
  274.  
  275. UBYTE FileOLM( short a, int b )
  276. {
  277.     cmess.arg1 = (ULONG)a;
  278.     cmess.arg2 = (ULONG)b;
  279.     CallHost( 23 );
  280.     return( (UBYTE)cmess.result );
  281. }
  282.  
  283. UBYTE Rnext( void )
  284. {
  285.     CallHost( 24 );
  286.     return( (UBYTE)cmess.result );
  287. }
  288.  
  289. void ParseCommandLine( UBYTE numargs )
  290. {
  291.     cmess.arg1 = (ULONG)numargs;
  292.     CallHost( 25 );
  293. }
  294.  
  295. short FindCommand( short num )
  296. {
  297.     cmess.arg1 = (ULONG) num;
  298.     CallHost( 26 );
  299.     return( (short)cmess.result );
  300. }
  301.  
  302. void ReadMessagePoint( char *a, long b )
  303. {
  304.     cmess.arg1 = (ULONG) a;
  305.     cmess.arg2 = (ULONG) b;
  306.     CallHost( 27 );
  307. }
  308.  
  309. void EditMessage( char *file )
  310. {
  311.     cmess.arg1 = (ULONG) file;
  312.     CallHost( 28 );
  313. }
  314.  
  315. void LoadText( BPTR fh )
  316. {
  317.     cmess.arg1 = (ULONG) fh;
  318.     CallHost( 29 );
  319. }
  320.  
  321. char WaitForInput( long mics )
  322. {
  323.     cmess.arg1 = (ULONG) mics;
  324.     CallHost( 31 );
  325.     return( (char)cmess.result );
  326. }
  327.  
  328. void AddCredits( UBYTE justadd, short m )
  329. {
  330.     cmess.arg1 = (ULONG)justadd;
  331.     cmess.arg2 = (ULONG)m;
  332.     CallHost( 33 );
  333. }
  334.  
  335. UBYTE SelectAndDownload( char *file, UBYTE now )
  336. {
  337.     cmess.arg1 = (ULONG)file;
  338.     cmess.arg2 = (ULONG)now;
  339.     CallHost( 39 );
  340.     return( (UBYTE)cmess.result );
  341. }
  342.  
  343. /* file: the ".vde" filename, without the ".vde"!
  344.    data: pointer to the structure you are going to edit
  345.    size: structure length in bytes
  346.  
  347.    returns: TRUE  if structure has been changed
  348.         FALSE otherwise
  349. */
  350.  
  351. short VisualDataEditor( char *file, void *data, long size )
  352. {
  353.     cmess.arg1 = (ULONG)file;
  354.     cmess.arg2 = (ULONG)data;
  355.     cmess.arg3 = (ULONG)size;
  356.     CallHost( 40 );
  357.     return( (short)cmess.result );
  358. }
  359.  
  360. void WriteLog( short n, char *text1, char *text2 )
  361. {
  362.     cmess.arg1 = (ULONG)n;
  363.     cmess.arg2 = (ULONG)text1;
  364.     cmess.arg3 = (ULONG)text2;
  365.     CallHost( 41 );
  366. }
  367.  
  368. /* 
  369.     In preparation for an ExtUpload, this function
  370.     sets the minimum number of free bytes to maintain on the
  371.     drive.
  372. */
  373.  
  374. void ExtSetMinFree( long free )
  375. {
  376.     cmess.arg1 = (ULONG)free;
  377.     CallHost( 42 );
  378. }
  379.  
  380. /*
  381.     In preparation for an ExtDownload or an ExtUpload, this function
  382.     sets the protocol to be used.  If you send NULL, it will allow the
  383.     user to choose his OWN protocol.
  384.  
  385.     Otherwise, you may select 'a' to be the first letter of a valid
  386.     system protocol (from BBSPROTO file), such as 'x', 'z', etc.
  387.  
  388.     TRUE will be returned if a protocol is selected and ready, FALSE
  389.     if there is a problem.
  390. */
  391.  
  392. UBYTE ExtSetProtocol( char a )
  393. {
  394.     cmess.arg1 = (ULONG)a;
  395.     CallHost( 43 );
  396.     return( (UBYTE)cmess.result );
  397. }
  398.  
  399. /* 
  400.     This routine allows the user to download the SINGLE file specified
  401.     by the FULL PATH 'args'.
  402.  
  403.     Currently, NULL is always returned.
  404. */
  405.  
  406. char *ExtDownload( char *args )
  407. {
  408.     cmess.arg1 = (ULONG)args;
  409.     CallHost( 44 );
  410.     return( (char *)cmess.result );
  411. }
  412.  
  413. /*
  414.     This routine allows the user to upload the file specified by
  415.     'args'.  The path for uploading will be taken from the path
  416.     in 'args'.  If you do NOT specify a path, the file(s) will
  417.     appear in the user's HOME directory.
  418.  
  419.     Note that with batch protocols like ZMODEM, the filename(s) are
  420.     taken from the header packet information, and may NOT be the
  421.     same as what you have requested the user upload.  For this reason,
  422.     you should have uploads occur in a TEMP directory, and search that
  423.     directory yourself for new files.
  424.  
  425.     Currently, NULL is always returned.
  426. */
  427.  
  428. char *ExtUpload( char *args )
  429. {
  430.     cmess.arg1 = (ULONG)args;
  431.     CallHost( 45 );
  432.     return( (char *)cmess.result );
  433. }
  434.  
  435. /* some commonly used functions in CNet */
  436.  
  437. short compstra( char *s, char *t )
  438. {
  439.     for( ; tolower(*s) == tolower(*t); s++, t++)
  440.         if( !*s ) return 0;
  441.  
  442.     return (short)( tolower(*s)-tolower(*t) );
  443. }
  444.  
  445. UBYTE PutQ( char *a )
  446. {
  447.     PutText( a );
  448.     return (UBYTE)(z->MCIcreg[0][0]=='1') ;
  449. }
  450.  
  451. void DoReturn( void )
  452. {
  453.     PutText("\n");
  454. }
  455.  
  456. void MakeEd( char *path )
  457. {
  458.     sprintf( path, "%s_edbuff%d", myp->gc.ZIPpath, z->InPort );
  459. }
  460.  
  461. void DeleteEd( void )
  462. {
  463.     char    filename[80];
  464.  
  465.     MakeEd    ( filename ) ;
  466.     DeleteFile( filename ) ;
  467. }
  468.  
  469. BPTR OpenEd( long mode )
  470. {
  471.     char    filename[80];
  472.  
  473.     MakeEd( filename );
  474.  
  475.     return Open( filename, mode );
  476. }
  477.  
  478. void PrepEditor( BPTR fp )
  479. {
  480.     BPTR    kp;
  481.     char    buff[100];
  482.  
  483.     if( fp ) {
  484.         if( kp = OpenEd( MODE_NEWFILE ) ) {
  485.             while( FGets( fp, buff, 82 ) && buff[0]!=26 )
  486.                    FPuts( kp, buff     ) ;
  487.  
  488.             Close( kp );
  489.         }
  490.     }
  491.     else    DeleteEd();
  492. }
  493.  
  494. void SaveEditor( BPTR fp, UBYTE eof )
  495. {
  496.     BPTR    kp;
  497.     char    buff[100];
  498.  
  499.     if( kp = OpenEd( MODE_OLDFILE ) ) {
  500.         while( FGets( kp, buff, 82 ) && buff[0]!=26 )
  501.                FPuts( fp, buff     ) ;
  502.  
  503.         Close( kp );
  504.  
  505.         DeleteEd();
  506.     }
  507.  
  508.     if( eof ) FPuts( fp, "\032\n" );
  509. }
  510.